<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\controller;

/**
 * 动态接口控制器
 */
class Trend extends ApiBase
{
	 /**
     * 动态添加
     */
    public function trendAdd()
    {        	
        return $this->apiReturn($this->logicTrend->trendAdd($this->param));
    }
    /**
     * 动态删除
     */
    public function delTrend()
    {
        return $this->apiReturn($this->logicTrend->delTrend($this->param));
    }
     /**
     * 动态列表
     */
    public function trend_list()
    {        	
        return $this->apiReturn($this->logicTrend->getTrendList($this->param));
    }
    /**
     * 点赞动态
     */
    public function zan()
    {
        return $this->apiReturn($this->logicTrend->getZan($this->param));
    }
    /**
     * 点赞动态
     */
    public function cancelZan()
    {
        return $this->apiReturn($this->logicTrend->cancelZan($this->param));
    }
    /**
     * 点赞列表
     */
    public function zanList()
    {
        return $this->apiReturn($this->logicTrend->getZanList($this->param));
    }
    /**
     * 个人简介
     */
    public function userRemark()
    {
        return $this->apiReturn($this->logicTrend->userRemark($this->param));
    }
    /**
     * 获得背景图
     */
    public function getRemark()
    {
        $data=$this->param;
        $info=db('user')->field('remark,trendImg,headimg,name')->where('id',$data['user_id'])->find();
        return $this->apiReturn($info);
    }
    /**
     * 背景上传
     */
    public function uploadImg()
    {
        $data=$this->param;
        $file = request()->file('image');
        $path=ROOT_PATH . 'public' . DS . 'upload' . DS .'extend' . DS .'trend';
        if($file){
            $info = $file->validate(['size'=>1024*1024*1,'ext'=>'jpg,png,gif,jpeg'])->move($path);
            if($info){
                $str='/upload/extend/trend/'.date('Ymd').'/'.$info->getFilename();
            }else{
                // 上传失败获取错误信息
                return $this->apiReturn([API_CODE_NAME => 1020001, API_MSG_NAME => $file->getError()]);
            }
        }
        $arr=array('trendImg'=>$str);
        if(!empty($data['user_id'])){
            $url=db('user')->where('id',$data['user_id'])->value('trendImg');
            @unlink($_SERVER['DOCUMENT_ROOT'].$url);
            db('user')->where('id',$data['user_id'])->update($arr);
        }
        return $this->apiReturn($arr);
    }
}
